
package cn.ljy.uem.service.impl;

import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.uem.dao.SchoolMajorGroupMapper;
import cn.ljy.uem.dao.SchoolMajorGroupTeacherMapper;
import cn.ljy.uem.dao.SchoolTeacherMapper;
import cn.ljy.uem.model.*;
import cn.ljy.uem.model.query.SchoolMajorGroupTeacherQuery;
import cn.ljy.uem.service.SchoolMajorGroupTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @description 专业群与群主关系的业务层接口
 * @author 王秋林
 * @date 2022-7-20 10:41
 */
@Service
@Slf4j
public class ISchoolMajorGroupTeacherService extends IBaseService<SchoolMajorGroupTeacher, SchoolMajorGroupTeacherQuery> implements SchoolMajorGroupTeacherService {

    @Autowired
    private SchoolMajorGroupTeacherMapper mapper;
    @Autowired
    private SchoolMajorGroupMapper schoolMajorGroupMapper;
    @Autowired
    private SchoolTeacherMapper schoolTeacherMapper;

    @Override
    protected void beforeGet(Serializable majorGroupId) {
    }

    @Override
    protected void beforeUpdate(SchoolMajorGroupTeacher schoolMajorGroupTeacher) {
    }

    @Override
    protected void beforeSave(SchoolMajorGroupTeacher schoolMajorGroupTeacher) {

    }

    @Override
    protected void beforeDelete(Serializable[] ids) {

    }

    protected void beforeFindAll(Integer majorGroupId){}

    @Override
    protected void afterFindAll(List<SchoolMajorGroupTeacher> list) {
        for (SchoolMajorGroupTeacher schoolMajorGroupTeacher : list) {
            //添加专业群关联属性
            if (schoolMajorGroupTeacher.getMajorGroupId() != null) {
                    //查找专业所属专业群
                    SchoolMajorGroup schoolMajorGroup = schoolMajorGroupMapper.findById(schoolMajorGroupTeacher.getMajorGroupId());
                    //赋值
                schoolMajorGroupTeacher.setSchoolMajorGroup(schoolMajorGroup);
                }
                //添加专业负责人信息
                if (schoolMajorGroupTeacher.getTeacherId() != null) {
                    //查找专业负责人信息
                    SchoolTeacher schoolTeacher = schoolTeacherMapper.findById(schoolMajorGroupTeacher.getTeacherId());
                    //赋值
                    schoolMajorGroupTeacher.setSchoolTeacher(schoolTeacher);
                }
            }
    }
}
